
#include "dxdiag_res.h"
#include "dxdiagcom.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);

/* System tab callback proceedure */
LRESULT CALLBACK System_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg) {
        case WM_INITDIALOG:
            return TRUE;
        default:
            break;
    }

    return FALSE;
}

BOOL SystemInfo_GetInfo(DxDiagCOM* pcom, SystemInfo* info)
{
    IDxDiagContainer* system;
    /* Get the system info container */
    if (FAILED(DxDiagCOM_GetContainer(pcom->root, (LPCWSTR)("DxDiag_SystemInfo"), &system)))
        return FALSE;

    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZTIMEENGLISH), &info->time);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZTIMELOCALIZED), &info->timeLocalized);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZMACHINENAMEENGLISH), &info->machineName);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZOSEXLOCALIZED), &info->operatingSystem);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZOSEXLONGLOCALIZED), &info->operatingSystemLong);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZLANGUAGESLOCALIZED), &info->languages);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZSYSTEMMANUFACTURERENGLISH), &info->systemManufacturer);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZSYSTEMMODELENGLISH), &info->systemModel);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZBIOSENGLISH), &info->bios);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZPROCESSORENGLISH), &info->processor);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZPHYSICALMEMORYENGLISH), &info->physicalMemory);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZPAGEFILELOCALIZED), &info->pageFile);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZWINDOWSDIR), &info->windowsDirectory);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZDIRECTXVERSIONLONGENGLISH), &info->directxVersion);
    DxDiagCOM_GetStringProperty(system, DxDiag_LoadString(SYSTEM_SZSETUPPARAMENGLISH), &info->directxSetup);

    return TRUE;
}

void System_DisplayData()
{
    HWND hWnd;

    /* Display the time */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_TIMEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.timeLocalized);

    /* Display the computer name */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_NAMEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.machineName);

    /* Display the operating system */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_OSDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.operatingSystem);

    /* Display the language info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_LANGDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.languages);

    /* Display the manufacturer info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_MFGDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.systemManufacturer);

    /* Display the model info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_MODELDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.systemModel);

    /* Display the bios info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_BIOSDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.bios);

    /* Display the proc info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_PROCDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.processor);

    /* Display the memory info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_RAMDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.physicalMemory);

    /* Display the page file info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_PAGEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.pageFile);

    /* Display the page file info */
    hWnd = GetDlgItem(hTabDisplay, SYSTEMTAB_DXDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)systemInfo.directxVersion);
}

void System_SaveText(FILE* pFile)
{
//    /* Write a header to the file */
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_HBAR));
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_SYSTEMINFORMATION));
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_HBAR));
//
//    /* Write the sysInfo data to the file */
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_TIMEOFTHISREPORT), systemInfo.time);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_MACHINENAME), systemInfo.machineName);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_OPERATINGSYSTEM), systemInfo.operatingSystemLong);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_LANGUAGE), systemInfo.languages);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_SYSTEMMANUFACTURER), systemInfo.systemManufacturer);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_SYSTEMMODEL), systemInfo.systemModel);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_BIOS), systemInfo.bios);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_PROCESSOR), systemInfo.processor);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_MEMORY), systemInfo.physicalMemory);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_PAGEFILE), systemInfo.pageFile);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_WINDOWSDIR), systemInfo.windowsDirectory);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_DIRECTXVERSION), systemInfo.directxVersion);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_DXSETUPPARAMETERS), systemInfo.directxSetup);
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_DXDIAGVERSION));
//    fwprintf(pFile, DxDiag_LoadString(SYSTEM_TEXT_NEWLINE));
}

void System_SaveXML(XML_Node* root)
{
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_TIME), systemInfo.time);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_MACHINENAME), systemInfo.machineName);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_OPERATINGSYSTEM), systemInfo.operatingSystemLong);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_LANGUAGE), systemInfo.languages);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_SYSTEMMANUFACTURER), systemInfo.systemManufacturer);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_SYSTEMMODEL), systemInfo.systemModel);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_BIOS), systemInfo.bios);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_PROCESSOR), systemInfo.processor);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_MEMORY), systemInfo.physicalMemory);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_PAGEFILE), systemInfo.pageFile);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_WINDOWSDIR), systemInfo.windowsDirectory);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_DIRECTXVERSION), systemInfo.directxVersion);
    XML_insertChildNode(root, (LPCWSTR)DxDiag_LoadString(SYSTEM_XML_DXSETUPPARAMETERS), systemInfo.directxSetup);
}
